package com.cloud.core.redis;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * 1Cloud1
 * @author Administrator
 * @since 2015-11-4
 * @version 1.0 
 */
@Component("RedisFactory")
public class RedisFactory {
	@Autowired
	private RedisPoolFactory RedisPoolFactory;
	private JedisPool jedisPool;
	
	@PostConstruct
	public void init(){
		jedisPool = RedisPoolFactory.getInstance();
	}

	/**
	 * @return
	 */
	public Jedis getInstance() {
		return jedisPool.getResource();
	}

	private JedisPool getJedisPool() {
		return jedisPool;
	}

	public void returnResource(Object obj) {
		getJedisPool().returnResource((Jedis)obj);
	}
	
	public void returnBrokenResource(Object obj) {
		getJedisPool().returnBrokenResource((Jedis)obj);
	}
}